#include "sence_config.h"

Sence_Config::Sence_Config(std::string file){
	
	config.ReadFromFile(file);
	
	if(config.EntryExists("game_timer_tick"))
		this->Game_Timer_Tick = config.GetLongIntEntry("game_timer_tick").second;

	if(config.EntryExists("background_tick_num"))
		this->Background_Tick_Num = config.GetLongIntEntry("background_tick_num").second;
	
	if(config.EntryExists("block_tick_num"))
		this->Block_Tick_Num = config.GetLongIntEntry("block_tick_num").second;
	
	if(config.EntryExists("building_tick_num"))
		this->Building_Tick_Num = config.GetLongIntEntry("building_tick_num").second;
	
	if(config.EntryExists("reward_tick_num"))
		this->Reward_Tick_Num = config.GetLongIntEntry("reward_tick_num").second;
	
	if(config.EntryExists("block_tick_per_pic"))
		this->Block_Tick_Per_Pic = config.GetLongIntEntry("block_tick_per_pic").second;

	if(config.EntryExists("building_tick_per_pic"))
		this->Building_Tick_Per_Pic = config.GetLongIntEntry("building_tick_per_pic").second;

	if(config.EntryExists("reward_tick_per_pic"))
		this->Reward_Tick_Per_Pic = config.GetLongIntEntry("reward_tick_per_pic").second;

	/*************************************************************************************************/
	
	if(config.EntryExists("background_num"))
		this->Background_Num = config.GetLongIntEntry("background_num").second;
	
	if(config.EntryExists("block_left_num"))
		this->Block_Left_Num = config.GetLongIntEntry("block_left_num").second;
	
	if(config.EntryExists("block_mid_num"))
		this->Block_Mid_Num = config.GetLongIntEntry("block_mid_num").second;
	
	if(config.EntryExists("block_right_num"))
		this->Block_Right_Num = config.GetLongIntEntry("block_right_num").second;
	
	if(config.EntryExists("building_left_num"))
		this->Building_Left_Num = config.GetLongIntEntry("building_left_num").second;
	
	if(config.EntryExists("building_right_num"))
		this->Building_Right_Num = config.GetLongIntEntry("building_right_num").second;
	
	if(config.EntryExists("reward_num"))
		this->Reward_Num = config.GetLongIntEntry("reward_num").second;
	
	/**********************************************************************************************************/
	
	if(config.EntryExists("background_folder"))
		this->BackgroundFolder = config.GetStringEntry("background_folder").second;
	
	if(config.EntryExists("block_left_folder"))
		this->Block_Left_Folder = config.GetStringEntry("block_left_folder").second;
	
	if(config.EntryExists("block_mid_folder"))
		this->Block_Mid_Folder = config.GetStringEntry("block_mid_folder").second;
	
	if(config.EntryExists("block_right_folder"))
		this->Block_Right_Folder = config.GetStringEntry("block_right_folder").second;
	
	if(config.EntryExists("building_left_folder"))
		this->Building_Left_Folder = config.GetStringEntry("building_left_folder").second;
	
	if(config.EntryExists("building_right_folder"))
		this->Building_Right_Folder = config.GetStringEntry("building_right_folder").second;
	
	if(config.EntryExists("reward_folder"))
		this->Reward_Folder = config.GetStringEntry("reward_folder").second;
	
	/***********************************************************************************************************/
	
	if(config.EntryExists("right_block_max_point"))
		this->Right_Block_Max_Point = this->Parse(config.GetStringEntry("right_block_max_point").second);
	
	if(config.EntryExists("right_block_min_point"))
		this->Right_Block_Min_Point = this->Parse(config.GetStringEntry("right_block_min_point").second);
	
	if(config.EntryExists("right_block_max_width"))
		this->Right_Block_Max_Width = config.GetLongIntEntry("right_block_max_width").second;
	
	if(config.EntryExists("right_block_min_width"))
		this->Right_Block_Min_Width = config.GetLongIntEntry("right_block_min_width").second;
	
	
	
	if(config.EntryExists("mid_block_max_point"))
		this->Mid_Block_Max_Point = this->Parse(config.GetStringEntry("mid_block_max_point").second);
	
	if(config.EntryExists("mid_block_min_point"))
		this->Mid_Block_Min_Point = this->Parse(config.GetStringEntry("mid_block_min_point").second);
	
	if(config.EntryExists("mid_block_max_width"))
		this->Mid_Block_Max_Width = config.GetLongIntEntry("mid_block_max_width").second;
	
	if(config.EntryExists("mid_block_min_width"))
		this->Mid_Block_Min_Width = config.GetLongIntEntry("mid_block_min_width").second;
	
	
	
	if(config.EntryExists("left_block_max_point"))
		this->Left_Block_Max_Point = this->Parse(config.GetStringEntry("left_block_max_point").second);
	
	if(config.EntryExists("left_block_min_point"))
		this->Left_Block_Min_Point = this->Parse(config.GetStringEntry("left_block_min_point").second);
	
	if(config.EntryExists("left_block_max_width"))
		this->Left_Block_Max_Width = config.GetLongIntEntry("left_block_max_width").second;
	
	if(config.EntryExists("left_block_min_width"))
		this->Left_Block_Min_Width = config.GetLongIntEntry("left_block_min_width").second;
	
	/***********************************************************************************************/
	
	
	if(config.EntryExists("right_reward_max_point"))
		this->Right_Reward_Max_Point = this->Parse(config.GetStringEntry("right_reward_max_point").second);
	
	if(config.EntryExists("right_reward_min_point"))
		this->Right_Reward_Min_Point = this->Parse(config.GetStringEntry("right_reward_min_point").second);
	
	if(config.EntryExists("right_reward_max_width"))
		this->Right_Reward_Max_Width = config.GetLongIntEntry("right_reward_max_width").second;
	
	if(config.EntryExists("right_reward_min_width"))
		this->Right_Reward_Min_Width = config.GetLongIntEntry("right_reward_min_width").second;
	
	
	
	if(config.EntryExists("mid_reward_max_point"))
		this->Mid_Reward_Max_Point = this->Parse(config.GetStringEntry("mid_reward_max_point").second);
	
	if(config.EntryExists("mid_reward_min_point"))
		this->Mid_Reward_Min_Point = this->Parse(config.GetStringEntry("mid_reward_min_point").second);
	
	if(config.EntryExists("mid_reward_max_width"))
		this->Mid_Reward_Max_Width = config.GetLongIntEntry("mid_reward_max_width").second;
	
	if(config.EntryExists("mid_reward_min_width"))
		this->Mid_Reward_Min_Width = config.GetLongIntEntry("mid_reward_min_width").second;
	
	
	
	if(config.EntryExists("left_reward_max_point"))
		this->Left_Reward_Max_Point = this->Parse(config.GetStringEntry("left_reward_max_point").second);
	
	if(config.EntryExists("left_reward_min_point"))
		this->Left_Reward_Min_Point = this->Parse(config.GetStringEntry("left_reward_min_point").second);
	
	if(config.EntryExists("left_reward_max_width"))
		this->Left_Reward_Max_Width = config.GetLongIntEntry("left_reward_max_width").second;
	
	if(config.EntryExists("left_reward_min_width"))
		this->Left_Reward_Min_Width = config.GetLongIntEntry("left_reward_min_width").second;
	
	/***********************************************************************************************/
	
	
	if(config.EntryExists("right_building_max_point"))
		this->Right_Building_Max_Point = this->Parse(config.GetStringEntry("right_building_max_point").second);
	
	if(config.EntryExists("right_building_min_point"))
		this->Right_Building_Min_Point = this->Parse(config.GetStringEntry("right_building_min_point").second);
	
	if(config.EntryExists("right_building_max_width"))
		this->Right_Building_Max_Width = config.GetLongIntEntry("right_building_max_width").second;
	
	if(config.EntryExists("right_building_min_width"))
		this->Right_Building_Min_Width = config.GetLongIntEntry("right_building_min_width").second;

	
	
	
	if(config.EntryExists("left_building_max_point"))
		this->Left_Building_Max_Point = this->Parse(config.GetStringEntry("left_building_max_point").second);
	
	if(config.EntryExists("left_building_min_point"))
		this->Left_Building_Min_Point = this->Parse(config.GetStringEntry("left_building_min_point").second);
	
	if(config.EntryExists("left_building_max_width"))
		this->Left_Building_Max_Width = config.GetLongIntEntry("left_building_max_width").second;
	
	if(config.EntryExists("left_building_min_width"))
		this->Left_Building_Min_Width = config.GetLongIntEntry("left_building_min_width").second;	
}

UI::UI_Point Sence_Config::Parse(const std::string& txt) const{
	UI::UI_Point p;
	std::vector<std::string> v = stdex::DetokenizeString(txt,",");
	if(v.size() > 1){
		p.SetX(stdex::atoi(stdex::TrimString(v[0])));
		p.SetY(stdex::atoi(stdex::TrimString(v[1])));
	}
	return p;
}
